package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.zzyl.common.core.domain.model.LoginBody;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.service.IContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component("updateContractStatusJob")
public class UpdateContractStatusJob {


    @Autowired
    private IContractService contractService;

    public void updateStatus(){
        //更新合同的状态  状态(0:未生效  1:已生效  2:已过期  3:已失效
        //未生效----已失效
        //update contract set status = 1 where status=0 and now() between start_date and end_date
        //update contract set status = 1 where status=0 and start_date > now() and end_date < now()

        LambdaUpdateWrapper<Contract> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Contract::getStatus,1);
        updateWrapper.eq(Contract::getStatus,0);
        updateWrapper.gt(Contract::getStartDate, LocalDateTime.now());
        updateWrapper.lt(Contract::getEndDate, LocalDateTime.now());

        //已生效----已过期
        // update contract set status = 2 where status = 1 and now() > end_date
        LambdaUpdateWrapper<Contract> updateWrapper1 = new LambdaUpdateWrapper<>();
        updateWrapper1.set(Contract::getStatus,2);
        updateWrapper1.eq(Contract::getStatus,1);
        updateWrapper1.gt(Contract::getStartDate, LocalDateTime.now());
        updateWrapper1.lt(Contract::getEndDate, LocalDateTime.now());

        log.info("执行了自己的定时任务");
    }
}
